$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'workflow/actModel/getActModelList',
        datatype: "json",
        colModel: [
			{ label: '模型编号', name: 'id', index: 'id', width: 100 },
			{ label: '模型名称', name: 'name', index: 'name', width: 100 },
            { label: '版本', name: 'version', index: 'version', width: 100 },
            { label: '创建时间', name: 'createTime', index: 'createTime', width: 100 }
        ],
		viewrecords: true,
        height: 365,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q:{

        },
		showList: true,
		title: null,
		model: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
			vm.title = "新增";
            vm.model = {};
		},
        edit: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            window.location.href = '/statics/workflow/modeler.html'+'?modelId='+id;
		},
        deploy: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            var url = '/workflow/actModel/deployActModel'+'?id='+id;
            $.ajax({
                type: "GET",
                url: baseURL + url,
                contentType: "application/json",
                success: function(r){
                    if(r.code === 0){
                        alert('添加成功', function (index) {
                            vm.reload();
                        });
                    }else{
                        alert(r.msg);
                    }
                }
            });
        },
        check: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }
            window.location.href = '/workflow/actModel/exportActModel'+'?id='+id;
        },
		save: function (event) {
            var url = "workflow/actModel/createActModel";
			$.ajax({
				type: "POST",
			    url: baseURL + url,
                // url: url,
			    contentType: "application/json",
			     data: JSON.stringify(vm.model),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
        getInfo: function (id) {
            $.get(baseURL + "legalprovisions/info/" + id, function (r) {
                vm.legalProvisions = r.legalProvisions;
            });
        },
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			if(ids.length>1){
                alert("请选择一条记录");
                return;
            }
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: baseURL + "workflow/actModel/deleteModel/"+ids[0],
				    contentType: "application/json",
				 //   data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		reload: function (event) {
			vm.showList = true;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{ 
                page:page,
                postData:{'queryname':vm.q.name}
            }).trigger("reloadGrid");
		}
	}
});